<?php
namespace Portal\Controller;
use Common\Controller\HomebaseController;

class MemberController extends HomebaseController {
	//清除会员因三次未签到产生的约课限制
	public function clear_unsignday() {
		//清除会员因三次未签到产生的约课限制
//		$Member=M('member');
//		$where['unsignday']=array('gt',1);
//		$msg=$Member->where($where)->setField('unsignday',null);
		//清除上月预定的订单中未签到的订单（使其不计入本月未签到统计）
		$Reserve=M('reserve');
		$where1['status']=3;
		$where1['sign']=1;
		//月初时间戳$beginThismonth
		$beginThismonth=mktime(0,0,0,date('m'),1,date('Y'));
		$beginThismonth=date('Y-m-d H:i:s',$beginThismonth);
		$where1['ordertime']=array('elt',$beginThismonth);

		$msg1=$Reserve->where($where1)->setField('status',5);
		if($msg1){
			echo "<script>alert('操作成功！');history.go(-1);</script>";
		}else{
			echo "<script>alert('操作失败！');history.go(-1);</script>";
		}
	}
    //添加新会员
	public function addmember() {
		$this->display(":addmember");
		if($_POST['name']&&$_POST['tel']&&$_POST['sex']){
			$arr=$_POST;
			$Member=M('member');
			$msg=$Member->add($arr);
			if($msg){
				$this->succ('showmember');
			}
			else{
				$this->err('showmember');
			}
		}
		else{
			echo '请添加信息！';
		}
	}
	//会员列表（修改、删除）
	public function clear(){
		$_POST=null;
		session("memberwhere['uid']",null);
		session("memberwhere['name']",null);
		session("memberwhere['tel']",null);
		session("memberwhere['s']",null);
		$this->showmember();
	}
	public function showmember() {
		$Member=M('member');
		//uid
		if($_POST['uid']){
			$where['uid']=$_POST['uid'];
			session("memberwhere['uid']",$where['uid']);
		}else if(!$_POST['uid'] && session("memberwhere['uid']")){
			$where['uid']=session("memberwhere['uid']");
		}
		//name
		if($_POST['name']){
			$where['name']=$_POST['name'];
			session("memberwhere['name']",$where['name']);
		}else if(!$_POST['name'] && session("memberwhere['name']")){
			$where['name']=session("memberwhere['name']");
		}
		//tel
		if($_POST['tel']){
			$where['tel']=$_POST['tel'];
			session("memberwhere['tel']",$where['tel']);
		}else if(!$_POST['tel'] && session("memberwhere['tel']")){
			$where['tel']=session("memberwhere['tel']");
		}
		//s
		if($_POST['s']){
			$where['s']=$_POST['s'];
			session("memberwhere['s']",$where['s']);
		}else if(!$_POST['s'] && session("memberwhere['s']")){
			$where['s']=session("memberwhere['s']");
		}
        $count=$Member->where($where)->count();
		$page=$this->page($count,10);
		$msg=$Member
		->where($where)
		->limit($page->firstRow , $page->listRows)
		->select();
		for($i=0;$i<count($msg);$i++){
			$msg[$i]['nick']=urldecode($msg[$i]['nick']);
		}
		$s='通用';
		$this->assign('s',$s)
		->assign("page", $page->show('Admin'))
		->assign('where',$where)
		->assign('msg',$msg);
    	$this->display(':showmember');
    }
	public function showmember1() {
		$Member=M('member');
		$where['s']='高新';
		if($_POST['uid']){
			$where['uid']=$_POST['uid'];
		}
		if($_POST['name']){
			$where['name']=$_POST['name'];
		}
		if($_POST['tel']){
			$where['tel']=$_POST['tel'];
		}
		if($_POST['s']){
			$where['s']=$_POST['s'];
		}
        $count=$Member->where($where)->count();
		$page=$this->page($count,10);
		$msg=$Member
		->where($where)
		->limit($page->firstRow , $page->listRows)
		->select();
		for($i=0;$i<count($msg);$i++){
			$msg[$i]['nick']=urldecode($msg[$i]['nick']);
		}
		$s='高新';
		$this->assign('s',$s)
		->assign("page", $page->show('Admin'))
		->assign('msg',$msg);
    	$this->display(':showmember');
    }
	public function showmember2() {
		$Member=M('member');
		$where['s']='二十四城';
		if($_POST['uid']){
			$where['uid']=$_POST['uid'];
		}
		if($_POST['name']){
			$where['name']=$_POST['name'];
		}
		if($_POST['tel']){
			$where['tel']=$_POST['tel'];
		}
		if($_POST['s']){
			$where['s']=$_POST['s'];
		}
        $count=$Member->where($where)->count();
		$page=$this->page($count,10);
		$msg=$Member
		->where($where)
		->limit($page->firstRow , $page->listRows)
		->select();
		for($i=0;$i<count($msg);$i++){
			$msg[$i]['nick']=urldecode($msg[$i]['nick']);
		}
		$s='二十四城';
		$this->assign('s',$s)
		->assign("page", $page->show('Admin'))
		->assign('msg',$msg);
    	$this->display(':showmember');
    }
	public function showmember3() {
		$Member=M('member');
		$where['s']='磨子桥';
		if($_POST['uid']){
			$where['uid']=$_POST['uid'];
		}
		if($_POST['name']){
			$where['name']=$_POST['name'];
		}
		if($_POST['tel']){
			$where['tel']=$_POST['tel'];
		}
		if($_POST['s']){
			$where['s']=$_POST['s'];
		}
        $count=$Member->where($where)->count();
		$page=$this->page($count,10);
		$msg=$Member
		->where($where)
		->limit($page->firstRow , $page->listRows)
		->select();
		for($i=0;$i<count($msg);$i++){
			$msg[$i]['nick']=urldecode($msg[$i]['nick']);
		}
		$s='磨子桥';
		$this->assign('s',$s)
		->assign("page", $page->show('Admin'))
		->assign('msg',$msg);
    	$this->display(':showmember');
    }
	public function showmember4() {
		$Member=M('member');
		$where['s']='凯旋广场';
		if($_POST['uid']){
			$where['uid']=$_POST['uid'];
		}
		if($_POST['name']){
			$where['name']=$_POST['name'];
		}
		if($_POST['tel']){
			$where['tel']=$_POST['tel'];
		}
		if($_POST['s']){
			$where['s']=$_POST['s'];
		}
        $count=$Member->where($where)->count();
		$page=$this->page($count,10);
		$msg=$Member
		->where($where)
		->limit($page->firstRow , $page->listRows)
		->select();
		for($i=0;$i<count($msg);$i++){
			$msg[$i]['nick']=urldecode($msg[$i]['nick']);
		}
		$s='凯旋广场';
		$this->assign('s',$s)
		->assign("page", $page->show('Admin'))
		->assign('msg',$msg);
    	$this->display(':showmember');
    }
	//删除会员
	public function delmember() {
		$uid=$_GET['uid'];
		$Member=M('member');
		$msg=$Member->where("uid='$uid'")->delete();//where语句中的变量需要引号
		if($msg){
			$this->succ('showmember');
		}
	}
	//编辑会员
	public function editmember() {
			$Member=M('member');
			$uid=$_GET['uid'];
			$msg=$Member->where("uid='$uid'")->select();
			$this->assign('msg',$msg);
			$this->display(":editmember");
			$arr=$_POST;
			
			if($arr['name']&&$arr['tel']&&$arr['sex']){
			//$arr['sitename']=$_POST['sitename'];
			//$arr['addr']=$_POST['addr'];
			//$arr['addrtel']=$_POST['addrtel'];
				$msg=$Member->where("uid='$uid'")->save($arr);
				if($msg){
					$this->succ('showmember');
				}
				else{
					$this->err('showmember');
				}
			}
	}
	//操作成功
	public function succ($m){
		$C='Member';
		$this->assign('m',$m)->assign('C',$C);
		$this->display(':success');
	}
	//操作失败
	public function err($m){
		$C='Member';
		$this->assign('m',$m)->assign('C',$C);
		$this->display(':err');
	}
}
